//
//  ZdshpbVC+UI.swift
//  Auscultation
//
//  Created by 来 on 2020/12/9.
//

import Foundation

extension ZdshpbVC {
    
    func initUI() {
        
        let top_view = UIImageView.init(image: #imageLiteral(resourceName: "beijing3@1.5x"))
        top_view.isUserInteractionEnabled = true
        view.addSubview(top_view)
        top_view.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(UIDevice.lgf_NavBarH())
        }
        self.navTitle = "自动派包"
        self.lgf_NavigationBar.style.lgf_TitleColor = UIColor.white
        self.lgf_NavigationBar.lgf_Reload()
        
        scrollView = UIScrollView.lgf_Table("FFFFFF")
        if #available(iOS 11.0, *) {
            scrollView.contentInsetAdjustmentBehavior = .never
        } else {
            self.automaticallyAdjustsScrollViewInsets = false
        }
        view.addSubview(scrollView)
        scrollView.snp.makeConstraints { (make) in
            make.top.equalTo(top_view.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
        
        let top = UIView.init()
        scrollView.addSubview(top)
        top.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(10)
            make.height.equalTo(20)
        }
        kbzyb = UILabel.init()
        kbzyb.isHidden = true
        kbzyb.text = "可审核样本：0"
        kbzyb.font = UIFont.systemFont(ofSize: 12)
        kbzyb.textColor = UIColor.init(lgf_HexString: "8D969D")
        top.addSubview(kbzyb)
        kbzyb.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        kbzyb2 = UILabel.init()
        kbzyb2.text = "可审核样本：0"
        kbzyb2.isHidden = false
        kbzyb2.font = UIFont.systemFont(ofSize: 12)
        kbzyb2.textColor = UIColor.init(lgf_HexString: "8D969D")
        top.addSubview(kbzyb2)
        kbzyb2.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        kbzry = UILabel.init()
        kbzry.text = "可审核人员：0"
        kbzry.font = UIFont.systemFont(ofSize: 12)
        kbzry.textColor = UIColor.init(lgf_HexString: "8D969D")
        top.addSubview(kbzry)
        kbzry.snp.makeConstraints { (make) in
            make.left.equalTo(kbzyb.snp.right).offset(20)
            make.centerY.equalToSuperview()
        }
        
        // 审核类型
        shlx = LGFLoginImageTitleView.init(nil, nil, left: 80, placeholder: "派包类型", text: "", true)
        shlx.delegate = self
        shlx.lgf_ViewName = "派包类型"
        shlx.text = "疑难"
        shlx.lgf_Name = "20"
        scrollView.addSubview(shlx)
        shlx.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.top.equalTo(top.snp.bottom).offset(10)
            make.height.equalTo(44.lgf_H())
        }
        let label4 = UILabel.init()
        label4.text = "派包类型"
        label4.textColor = UIColor.init(lgf_HexString: "222222")
        label4.font = UIFont.boldSystemFont(ofSize: 16)
        shlx.addSubview(label4)
        label4.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.bottom.equalToSuperview()
        }
        
        // 样本数量
        ybsl = LGFLoginImageTitleView.init(nil, nil, left: 80, placeholder: "样本数量", text: "", false)
        ybsl.textField.keyboardType = .numberPad
        ybsl.delegate = self
        scrollView.addSubview(ybsl)
        ybsl.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.top.equalTo(shlx.snp.bottom).offset(10)
            make.height.equalTo(44.lgf_H())
        }
        let label1 = UILabel.init()
        label1.text = "样本数量"
        label1.textColor = UIColor.init(lgf_HexString: "222222")
        label1.font = UIFont.boldSystemFont(ofSize: 16)
        ybsl.addSubview(label1)
        label1.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.bottom.equalToSuperview()
        }
        
        // 抽查数量
        ccsl = LGFLoginImageTitleView.init(nil, nil, left: 80, placeholder: "抽查数量", text: "", false)
        ccsl.textField.keyboardType = .numberPad
        ccsl.isHidden = true
        ccsl.delegate = self
        scrollView.addSubview(ccsl)
        ccsl.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.top.equalTo(ybsl.snp.bottom).offset(10)
            make.height.equalTo(0)
        }
        let label6 = UILabel.init()
        label6.text = "抽查数量"
        label6.textColor = UIColor.init(lgf_HexString: "222222")
        label6.font = UIFont.boldSystemFont(ofSize: 16)
        ccsl.addSubview(label6)
        label6.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.bottom.equalToSuperview()
        }
        
        // 样本规则
        ybgz = LGFLoginImageTitleView.init(nil, #imageLiteral(resourceName: "icon_arrow"), left: 80, placeholder: "样本规则", text: "", true)
        ybgz.delegate = self
        ybgz.lgf_ViewName = "样本规则"
        scrollView.addSubview(ybgz)
        ybgz.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.top.equalTo(ccsl.snp.bottom)
            make.height.equalTo(44.lgf_H())
        }
        let label3 = UILabel.init()
        label3.text = "样本规则"
        label3.textColor = UIColor.init(lgf_HexString: "222222")
        label3.font = UIFont.boldSystemFont(ofSize: 16)
        ybgz.addSubview(label3)
        label3.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.bottom.equalToSuperview()
        }
        
        // 人员规则
        rygz = LGFLoginImageTitleView.init(nil, #imageLiteral(resourceName: "icon_arrow"), left: 80, placeholder: "人员规则", text: "", true)
        rygz.delegate = self
        rygz.lgf_ViewName = "人员规则"
        scrollView.addSubview(rygz)
        rygz.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.top.equalTo(ybgz.snp.bottom).offset(10)
            make.height.equalTo(44.lgf_H())
        }
        let label5 = UILabel.init()
        label5.text = "人员规则"
        label5.textColor = UIColor.init(lgf_HexString: "222222")
        label5.font = UIFont.boldSystemFont(ofSize: 16)
        rygz.addSubview(label5)
        label5.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.bottom.equalToSuperview()
        }
        
        let button1 = UIButton.init(type: .custom)
        button1.backgroundColor = UIColor.init(lgf_HexString: EWEDarkMode.c_0F88F2)!
        button1.setTitle("确定", for: .normal)
        button1.setTitleColor(EWEDarkMode.white(), for: .normal)
        button1.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        button1.layer.cornerRadius = 4
        button1.layer.masksToBounds = true
        button1.addTarget(self, action: #selector(ZdshpbVC.queding(_:)), for: .touchUpInside)
        scrollView.addSubview(button1)
        button1.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.width.equalToSuperview().offset(-75)
            make.height.equalTo(44)
            make.top.equalTo(rygz.snp.bottom).offset(150)
        }
        
        scrollView.lgf_AutoContentSize(0)
    }
    
}

extension ZdshpbVC: LGFLoginImageTitleViewDelegate {
    func selectLGFLoginImageTitleView(_ view: LGFLoginImageTitleView) {
        self.view.endEditing(true)
        if view.lgf_ViewName == "派包类型" {
//            let picker = LGFBottomPickerView()
//            let data = ["疑难", "待审核"]
//            let sindex = data.lgf_IndexOfObject(self.shlx.textField.text ?? "疑难")
//            picker.showIn(self.view, data, sindex) { [weak self] (view, name, index) in
//                if index == 0 {
//                    self?.ccsl.isHidden = true
//                    self?.kbzyb.isHidden = true
//                    self?.kbzyb2.isHidden = false
//                    self?.ccsl.snp.updateConstraints({ (make) in
//                        make.height.equalTo(0)
//                    })
//                    self?.ybgz.snp.updateConstraints({ (make) in
//                        make.top.equalTo(self!.ccsl.snp.bottom)
//                    })
//                } else {
//                    self?.ccsl.isHidden = false
//                    self?.kbzyb.isHidden = false
//                    self?.kbzyb2.isHidden = true
//                    self?.ccsl.snp.updateConstraints({ (make) in
//                        make.height.equalTo(44.lgf_H())
//                    })
//                    self?.ybgz.snp.updateConstraints({ (make) in
//                        make.top.equalTo(self!.ccsl.snp.bottom).offset(10)
//                    })
//                }
//                self?.shlx.text = data[index]
//                self?.shlx.lgf_Name = ((index + 1) * 10).description
//            }
        } else if view.lgf_ViewName == "样本规则" {
            let picker = LGFBottomPickerView()
            let data = ["随机", "正序", "倒序"]
            let sindex = data.lgf_IndexOfObject(self.ybgz.textField.text ?? "正序")
            picker.showIn(self.view, data, sindex) { [weak self] (view, name, index) in
                self?.ybgz.text = data[index]
                self?.ybgz.lgf_Name = ((index + 1) * 10).description
            }
        } else if view.lgf_ViewName == "人员规则" {
            let picker = LGFBottomPickerView()
            let data = ["随机"]
            picker.showIn(self.view, data, 0) { [weak self] (view, name, index) in
                self?.rygz.text = data[index]
                self?.rygz.lgf_Name = ((index + 1) * 10).description
            }
        }
    }
}

